package com.bjsxt.Generic;

public class MethodGeneric {
    public  <T> void setName(T name){
        System.out.println(name);
    }

    public <T> T getName(T name){
        return name;
    }

//    静态方法不能使用类的泛型，只能使用方法的泛型
//    普通方法可以使用类的泛型，也能使用方法的泛型
    public static <T> void setFlag(T flag){
        System.out.println(flag);
    }
    public static <T> T getFlag(T flag){
        return flag;
    }

    public <T> void method(T...args){ //泛型方法与可变参数
        for (T t:args){
            System.out.println(t);
        }
    }
}
class Test3{

    public static void main(String[] args) {

        MethodGeneric methodGeneric = new MethodGeneric();
        methodGeneric.setName("xkdftg");
        methodGeneric.setName(123);
        MethodGeneric methodGeneric1 = new MethodGeneric();
        String s =methodGeneric1.getName("sdhgf");
        Integer i =methodGeneric1.getName(345);
        System.out.println(s);
        System.out.println(i);

        MethodGeneric.getFlag("sdtf");
        MethodGeneric.getFlag(123);
        MethodGeneric.setFlag("edfew");
        MethodGeneric.setFlag(346);

        MethodGeneric methodGeneric2 = new MethodGeneric();
        String[] arr = new String[]{"q","ew","wd"};
        methodGeneric2.method(arr);



    }

}
